home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers1.zip / IO16.ASM < prev    next >
Assembly Source File  |  1992-01-13  |  2KB  |  80 lines

  1. ;input a word from IO port
  2. inw    macro
  3.     in    ax,dx            ;read IO port
  4.     endm
  5.  
  6. ;write a word to an IO port
  7. outw    macro
  8.     out    dx,ax            ;write IO port
  9.     endm
  10.  
  11. ;this code inputs from a port that can accept either byte or word transfers.
  12. ;if the board is in a 8-bit slot, it always receives byte transfers.
  13. ;if the board is in a 16-bit slot, it has the IOCS16 line asserted on word I/O.
  14.  
  15. repinsw:
  16. ; If buffer doesn't begin on a word boundary, get the first byte
  17.     test    di,1            ; if(buf & 1){
  18.     jz    ibufeven        ;
  19.     in    al,dx            ; al = in(dx);
  20.     stosb                ; *di++ = al
  21.     dec    cx            ; cx--;
  22.     je    icnteven
  23. ibufeven:
  24.     cmp    is_186,0        ; Can we use rep insw?
  25.     je    repinsw_1        ; no - have to do it slowly.
  26.     shr    cx,1            ; cx = cnt >> 1; (convert to word count)
  27.     .286
  28.     rep    insw
  29.     .8086
  30.     jmp    short inobuf
  31. repinsw_1:
  32. ; Do the bulk of the buffer, a word at a time
  33.     shr    cx,1            ; cx = cnt >> 1; (convert to word count)
  34.     jcxz    inobuf            ; if(cx != 0){
  35. rb:    in    ax,dx            ; do { al = in(dx);
  36.     stosw                ; *si++ = ax; (di is word pointer)
  37.     loop    rb            ; } while(--cx != 0);
  38. ; now check for odd trailing byte
  39. inobuf:
  40.     jnc    icnteven
  41.     in    al,dx
  42.     stosb                ; *di++ = al
  43. icnteven:
  44.     ret
  45.  
  46.  
  47. ;this code outputs to a port that can accept either byte or word transfers.
  48. ;if the board is in a 8-bit slot, it always receives byte transfers.
  49. ;if the board is in a 16-bit slot, it has the IOCS16 line asserted on word I/O.
  50.  
  51. repoutsw:
  52.     test    si,1            ; (buf & 1) ?
  53.     jz    obufeven        ; no
  54.     lodsb                ; al = *si++;
  55.     out    dx,al            ; out(dx,al);
  56.     dec    cx            ; cx--;
  57.     je    ocnteven
  58. obufeven:
  59.     cmp    is_186,0        ; Can we use rep outsb?
  60.     je    out86            ; no - have to do it slowly.
  61.     shr    cx,1            ; cx = cnt >> 1; (convert to word count)
  62.     .286
  63.     rep    outsw
  64.     .8086
  65.     jmp    short onobuf
  66. out86:
  67.     shr    cx,1            ; cx = cnt >> 1; (convert to word count)
  68. ; Do the bulk of the buffer, a word at a time
  69.     jcxz    onobuf            ; if(cx != 0){
  70. xb:    lodsw                ; do { ax = *si++; (si is word pointer)
  71.     out    dx,ax
  72.     loop    xb            ; } while(--cx != 0); }
  73. ; now check for odd trailing byte
  74. onobuf:
  75.     jnc    ocnteven
  76.     lodsb                ;   out(dx,*si++);
  77.     out    dx,al
  78. ocnteven:
  79.     ret
  80.